/*
 * @Description:路由
 * @Version: 2.0
 * @Author: zhao
 * @Date: 2022-06-13 14:37:16
 * @LastEditors: zhao
 * @LastEditTime: 2022-07-08 10:24:47
 */
import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    // 登录
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  //注册
  {
    path: '/Register',
    component: () => import('@/views/Register'),
    hidden: true
  },
  //修改密码
  {
    path: '/setPassword',
    component: () => import('@/views/setPassword'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    redirect: '/home',
    component: Layout,
    children: [{
      path: '/home',
      name: 'home',
      component: () => import('@/views/home/index'),
      meta: { title: '首页', icon: 'el-icon-s-home' }
    },
    {
      path: '/AttributeQuery',
      name: 'AttributeQuery',
      component: () => import('@/views/AttributeQuery/index'),
      meta: { title: '属性查询' ,
              // keepAlive: true,
              // isBack: false,
            }
    },
    {
      path: '/SpatialRetrieval',
      name: 'SpatialRetrieval',
      component: () => import('@/views/SpatialRetrieval/index'),
      meta: { title: '空间检索',
              // keepAlive: true,
              // isBack: false,
            }
      //  keepAlive: true  需要缓存上一页面的数据,但是加了这个会导致返回后地图选取功能丧失
    },
    {
      path: '/FileInfoDetails',
      name: 'FileInfoDetails',
      component: () => import('@/views/FileInfoDetails'),
      meta: { title: '档案信息详情',
              //  keepAlive: true,
              // isBack: false,
            }
    },

    {
      path: '/Borrow',
      name: 'Borrow',
      component: () => import('@/views/Borrow'),
      meta: { title: '借阅车' }
    },
    {
      path: '/BorrowForm',
      name: 'BorrowForm',
      component: () => import('@/views/BorrowForm'),
      meta: { title: '借阅单' }
    },
    {
      path: '/BorrowFormDetail',
      name: 'BorrowFormDetail',
      component: () => import('@/views/BorrowForm/details/index.vue'),
      meta: { title: '借阅单详情' }
    },
    {
      path: '/UserInfo',
      name: 'UserInfo',
      component: () => import('@/views/UserInfo'),
      meta: { title: '个人信息' }
    },
    {
      path: '/InfoPublic',
      name: 'InfoPublic',
      component: () => import('@/views/InfoPublic'),
      meta: { title: '信息公告' }
    },
    {
      path: '/InfoPublic/details',
      name: 'InfoPublic/details',
      component: () => import('@/views/InfoPublic/details'),
      meta: { title: '信息公告详情' }
    },
    {
      path: '/BrowseRecord',
      name: 'BrowseRecord',
      component: () => import('@/views/BrowseRecord'),
      meta: { title: '浏览记录' }
    },
    {
      path: '/AboutUs',
      name: 'AboutUs',
      component: () => import('@/views/AboutUs'),
      meta: { title: '关于我们' }
    },
    {
      path: '/Process',
      name: 'Process',
      component: () => import('@/views/process'),
      meta: { title: '业务流程' }
    },
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history',
  // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
